#include "pingpong.h"

pingpong::pingpong(QGraphicsView *parent) : QGraphicsView(parent)
{
    scene = new QGraphicsScene();
    scene->setSceneRect(0,0,400,300);
    scene->addRect(0,0,400,300, QPen(Qt::SolidLine));
    playball= new Ball(100,75,10);
    scene->addItem(playball);
    setScene(scene);
    setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    setRenderHint(QPainter::Antialiasing);
   // setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    newgameButton = new QPushButton("Uusi peli", this);
    optionsButton = new QPushButton("Asetukset", this);
    highscoreButton = new QPushButton("Parhaat tulokset", this);

    buttonLayout = new QVBoxLayout();
    buttonLayout->setAlignment(Qt::AlignRight|Qt::AlignCenter);
    buttonLayout->addWidget(newgameButton);
    buttonLayout->addWidget(optionsButton);
    buttonLayout->addWidget(highscoreButton);

    setLayout(buttonLayout);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    timer = new QTimer(this);
    timer->start(30);
    connect(timer, SIGNAL(timeout()), scene, SLOT(advance()));
}
pingpong::~pingpong()
{
    scene->deleteLater();
}
